package com.cgnpc.scp.common.utils;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.cgnpc.scp.common.bean.MyPageResult;
import com.cgnpc.scp.manager.mybatis.entity.ProcessInfo;
import com.github.pagehelper.PageInfo;

public class MyPageResultUtil {

    public static <T> MyPageResult<T> createMyPageResult(PageInfo<T> pageResult) {
        MyPageResult<T> myPageResult = new MyPageResult<>();

        myPageResult.setTotalRows(pageResult.getTotal());
        myPageResult.setResults(pageResult.getList());

        return myPageResult;
    }

    public static <T> MyPageResult<T> createMyPageResultPlus(IPage<T> ipage) {
        PageInfo<T> pageResult = new PageInfo<>(ipage.getRecords());
        pageResult.setTotal(ipage.getTotal());

        MyPageResult<T> myPageResult = new MyPageResult<>();

        myPageResult.setTotalRows(pageResult.getTotal());
        myPageResult.setResults(pageResult.getList());

        return myPageResult;
    }

}
